<?php

namespace VEKA\ProjetBundle\Controller;

use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use VEKA\ProjetBundle\Entity\Chassis;

class ProjetController extends Controller
{
       public function indexAction()
    {
        return $this->render('VEKAProjetBundle:Projet:index.html.twig');
    }
	
	public function chassisAction()
	{
		$queryChassis = $this->getDoctrine()->getManager()->getRepository('VEKAProjetBundle:chassis');
		$listeChassis = $queryChassis->findAll();
		
		$queryFinition = $this->getDoctrine()->getManager()->getRepository('VEKAProjetBundle:Finition');
		$listeFinitions = $queryFinition->findAll();

		$queryCouleur = $this->getDoctrine()->getManager()->getRepository('VEKAProjetBundle:Couleur');
		$listeCouleurs = $queryCouleur->findAll();
		
		return $this->render('VEKAProjetBundle:Projet:chassis.html.twig', array('listeChassis' => $listeChassis,'listeFinitions' => $listeFinitions,'listeCouleurs'=>$listeCouleurs));
	}
	
	public function calculAction(){
	
		$queryFinition = $this->getDoctrine()->getManager()->getRepository('VEKAProjetBundle:Finition');
		$listeFinitions = $queryFinition->findAll();
		
		$queryVitrage = $this->getDoctrine()->getManager()->getRepository('VEKAProjetBundle:Vitrage');
		$listeVitrages = $queryVitrage->findAll();

		
		$queryChassis = $this->getDoctrine()->getManager()->getRepository('VEKAProjetBundle:chassis');
		$listeChassis = $queryChassis->findOneBy(array('url' => $_POST["TypeChassis"]));
		
		$queryCouleur = $this->getDoctrine()->getManager()->getRepository('VEKAProjetBundle:Couleur');
		$listeCouleurs = $queryCouleur->findAll();
		
		
		return $this->render('VEKAProjetBundle:Projet:calcul.html.twig', array('listeFinitions' => $listeFinitions, 'listeVitrages'=>$listeVitrages, 'chassis' => $listeChassis, 'listeCouleurs'=>$listeCouleurs, 'post' => htmlspecialchars($_POST["TypeChassis"])));
		
	}
	public function imprimerAction()
    {
	//$content = $this->render('VEKAProjetBundle:Projet:imprimer.html.twig');
	//print_r($_POST);
	ob_start();
    include(dirname(__FILE__).'/rapport/rapport.php');
	
	displayPDF();
    $content = ob_get_clean();
    require_once(dirname(__FILE__).'/html2pdf.class.php');
    $html2pdf = new \HTML2PDF('P','A4','fr');
	$html2pdf->pdf->SetDisplayMode('fullpage');
    $html2pdf->WriteHTML($content);
    $html2pdf->Output('rapport.pdf');
	$html2pdf->exit();
    }
}